package com.xqls.server.dto.recive;

import com.xqls.biz.SokectBiz;
import com.xqls.server.dto.SoketCommonDto;
import com.xqls.server.netty.DecoderUtil;
import com.xqls.util.ContextUtil;
import io.netty.buffer.ByteBuf;

/**
 * 阀门控制仪实时状态
 */
public class ControlApparatusDto  extends SoketCommonDto {

    /**
     * 阀门角度
     */
    private  Integer angle;

    /**
     * 仪器电源状态，0表示电源正常，1表示断电
     */
    private Integer powerStatus;
    /**
     * 浮球状态，0表示无信号，1表示有信号
     */
    private Integer floatingBallStatus;

    /**
     * 阀门控制模式
     */
    private Integer  model;
    /**
     * 当前发生故障后阀门处理方式
     */
    private Integer  process;

    public Integer getAngle() {
        return angle;
    }

    public void setAngle(Integer angle) {
        this.angle = angle;
    }

    public Integer getPowerStatus() {
        return powerStatus;
    }

    public void setPowerStatus(Integer powerStatus) {
        this.powerStatus = powerStatus;
    }

    public Integer getFloatingBallStatus() {
        return floatingBallStatus;
    }

    public void setFloatingBallStatus(Integer floatingBallStatus) {
        this.floatingBallStatus = floatingBallStatus;
    }

    public Integer getModel() {
        return model;
    }

    public void setModel(Integer model) {
        this.model = model;
    }

    public Integer getProcess() {
        return process;
    }

    public void setProcess(Integer process) {
        this.process = process;
    }

    protected void decode(ByteBuf in, SoketCommonDto soketCommonDto){
        ControlApparatusDto controlApparatusDto=(ControlApparatusDto)soketCommonDto;
        controlApparatusDto.setAngle(DecoderUtil.byteToInt(in.readByte()));
        String bitStr= DecoderUtil.byteToBit(in.readByte());
        controlApparatusDto.setPowerStatus(DecoderUtil.bitToInteger(bitStr,6));
        controlApparatusDto.setFloatingBallStatus(DecoderUtil.bitToInteger(bitStr,0));
        controlApparatusDto.setModel(DecoderUtil.byteToInt(in.readByte()));
        controlApparatusDto.setProcess(DecoderUtil.byteToInt(in.readByte()));
        super.decode(in,soketCommonDto);
    }


    public void operate( ){
        SokectBiz  sokectBiz=(SokectBiz) ContextUtil.getBean(SokectBiz.class);
        sokectBiz.controlApparatusRecive(this);
    }
}
